package com.softtek.gui;

import java.awt.FlowLayout;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.softtek.webbrowser.JBProperties;

public class AddressBar extends JPanel {
	
	private static final long serialVersionUID = -5640248549283100231L;

	private JButton backBtn;
	private JButton forwardBtn;
	
	private JTextField addressField;
	private ActionListener listener;
	
	public AddressBar(final ActionListener listener){
		super(new FlowLayout(FlowLayout.LEFT));
		this.listener = listener;
		
		buildBar();
	}
	
	private void buildBar(){
		
		String tmpImageFolderPath = JBProperties.getProperties().getProperty("APP_DIR") +
									JBProperties.getProperties().getProperty("ASSET_DIR") +
									JBProperties.getProperties().getProperty("IMAGE_DIR");
		
		backBtn = new JButton(new ImageIcon(tmpImageFolderPath + JBProperties.getProperties().getProperty("BTN_BACK_ICON")));
		forwardBtn = new JButton(new ImageIcon(tmpImageFolderPath + JBProperties.getProperties().getProperty("BTN_FRWD_ICON")));
		
		backBtn.setToolTipText("Go to previous page");
		forwardBtn.setToolTipText("Go to next page");
		
		backBtn.addActionListener(listener);
		forwardBtn.addActionListener(listener);

		addressField = new JTextField(75);
		addressField.addActionListener(listener);

		add(backBtn);
		add(forwardBtn);
		add(addressField);
	}

	public JButton getBackBtn() {
		return backBtn;
	}

	public JButton getForwardBtn() {
		return forwardBtn;
	}
	
	public JTextField getAddressField() {
		return addressField;
	}
	
}
